<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<style type="text/css">
body { overflow: hidden; font-family: Arial, 'Microsoft Yahei' !important; background-color: #3F4754 !important; color: #fff; overflow: auto; }
a { color: #fff; text-align: center; text-decoration: none; display: block; background-color: #4D596C; padding: 15px; border-radius: 3px; width: 160px; margin: 30px auto; }
a:active { background-color: #424D5F; border-radius: 3px; }
.title { text-align: center; font-size: 22px; }
.logo { background: url(logo.jpg) no-repeat; height: 100px; background-size: auto 100%; background-position: center; margin: 50px 0 0 0; }
.version { text-align: center; }
</style>
</head>

<body>
<div class="logo"></div>
<p class="title">中宏保险POC</p>

<p class="version">选择版本：<select name="" id="versionSelect"></select></p>

<a id="androidLink" href="">Android下载</a>
<a id="iOSLink" href="">iOS下载</a>

<script type="text/javascript">
var VersionCtrl = {
	// 远程下载地址，前缀
	remoteDownloadUrl: 'https://gitee.com/CheneyHu/Manulife/raw/master/release/',
	// 版本列表
	versionList: [{
    version: '1.0.0',
    date: '20171204'
  }],
	versionSelect: document.getElementById('versionSelect'),
	androidLink: document.getElementById('androidLink'),
	iOSLink: document.getElementById('iOSLink'),
	// 渲染下载select
	renderVersionSelection: function() {
		var self = this,
			versionList = self.versionList,
			versionSelect = self.versionSelect;

		for (var i = 0; i < versionList.length; i++) {
			var item = versionList[i];
			versionSelect.options.add(new Option('v'+item.version, item.version));
		}
	},
	// select change事件监听
	selectEventHandler: function() {
		var self = this,
			versionList = self.versionList,
			androidLink = self.androidLink,
			iOSLink = self.iOSLink,
			versionSelect = self.versionSelect;

		versionSelect.addEventListener('change', function(e) {
			var index = versionSelect.selectedIndex,
				value = versionSelect.options[index].value;
			for (var i = 0; i < versionList.length; i++) {
				var item = versionList[i];
				if (value == item.version) {
					self.setDownloadUrl(item);
				}
			}
		});
	},
	// 设置下载链接
	setDownloadUrl: function(item) {
		var version = item.version,
			date = item.date,
			prefix = this.remoteDownloadUrl;

		var androidDownloadUrl = prefix + date + '/Manulife~v'+ version +'.apk',
			iosDownloadUrl = 'itms-services://?action=download-manifest&url=' + prefix + date + '/ios.plist';

		this.androidLink.setAttribute('href', androidDownloadUrl);
		this.iOSLink.setAttribute('href', iosDownloadUrl);
	},
	init: function() {
		this.selectEventHandler();
		this.renderVersionSelection();
		this.setDownloadUrl(this.versionList[0]);
	}
};
VersionCtrl.init();
</script>
</body>
</html>